package com.cheyunkeji.er.adapter.evaluate;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cheyun.netsalev3.R;
import com.cheyunkeji.er.adapter.MyBaseAdapter;
import com.cheyunkeji.er.bean.evaluate.CustomerArchiveInfo;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Michael on 2017/2/16 15:45.
 */

public class CarOwnerArchiveAdapter extends MyBaseAdapter {

    public CarOwnerArchiveAdapter(ArrayList<CustomerArchiveInfo> dataList, Context context) {
        super(dataList, context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        final ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.er_evaluate_carowner_archive_lv_item, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        if (position % 2 != 0)
            convertView.setBackgroundColor(Color.parseColor("#fbfbfb"));
        else
            convertView.setBackgroundColor(Color.parseColor("#ffffff"));

        CustomerArchiveInfo itemBean = (CustomerArchiveInfo) dataList.get(position);
        holder.tvOwnerName.setText(itemBean.getRealname());
        holder.tvTeleNumber.setText(itemBean.getPhone());
        holder.tvAddress.setText(itemBean.getAddress());

        if(itemBean.getSex().equals("1")) {
            holder.ivGender.setImageResource(R.mipmap.er_icon_male_white);
            holder.ivGender.setBackgroundResource(R.drawable.er_bkg_dark_blue_rect);
        }
        else {
            holder.ivGender.setImageResource(R.mipmap.er_icon_female_white);
            holder.ivGender.setBackgroundResource(R.drawable.er_bkg_pink_rect);
        }

        if(itemBean.getCategory().equals("1"))
            holder.ivPersonalOrCompany.setImageResource(R.mipmap.er_icon_user_personal);
        else if(itemBean.getCategory().equals("2"))
            holder.ivPersonalOrCompany.setImageResource(R.mipmap.er_icon_company);
        else
            holder.ivPersonalOrCompany.setImageResource(R.mipmap.er_icon_xzdw_white);

        return convertView;

    }


    static class ViewHolder {
        @BindView(R.id.tv_owner_name)
        TextView tvOwnerName;
        @BindView(R.id.iv_personal_or_company)
        ImageView ivPersonalOrCompany;
        @BindView(R.id.iv_gender)
        ImageView ivGender;
        @BindView(R.id.rl_img_display)
        RelativeLayout rlImgDisplay;
        @BindView(R.id.tv_tele_number)
        TextView tvTeleNumber;
        @BindView(R.id.tv_address)
        TextView tvAddress;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
